<%@page import="model.entity.product.Product"%>
<%@page import="util.GeneralUtil"%>
<%@page import="model.entity.product.Phone"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="kendo" uri="http://www.kendoui.com/jsp/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8" />
<title>Manager Panel</title>

<%@include file="headerLink.jsp" %>
<script type="text/javascript">
$(document).ready(function() {
	$(".numeric").kendoNumericTextBox();
});
</script>
</head>


<body>
	<% request.setAttribute("type", "Phone");
		request.setAttribute("fieldMap", Phone.fieldMap());%>
	<%
		if (session.getAttribute("manager") == null) {
			Map<String, Class<?>> fieldMap = (Map<String, Class<?>>) request.getAttribute("fieldMap");
			String type = (String) request.getAttribute("type");
			
			String updateUrl = "../ProductContr?command=update&type="+type;
			String createUrl = "../ProductContr?command=create&type="+type;
	%>

	<jsp:include page="header.jsp"></jsp:include>

	<jsp:include page="menu.jsp"></jsp:include>

	<section id="main" class="column">
		<div style="width: 300px;margin: auto;">
		<form action="<%=createUrl%>" method="post">
			<table>
				<% for(Entry<String, Class<?>> entry : fieldMap.entrySet()) {
					String html = GeneralUtil.generateInputDepenOnType(entry.getValue(), entry.getKey(), false);%>
				<tr>
					<td><%=entry.getKey() %></td>
					<td>

						<%if(html != null) {%><%= html%><% } else {
						%>
							<input type="text" name="<%=entry.getKey()%>"/>
							<%=entry.getValue().getSimpleName() %>
						<%  } %>
						
					</td>
				</tr>
				<% } %>
				<tr>
					<td>
						<input type="submit" value="Ok"/>
					</td>
				</tr>
			</table>
		</form>
		</div>
	</section>
	<%
		} else {
	%>
	<script type="text/javascript">
		$.confirm({
			'title' : 'Not Authorized',
			'message' : 'You need to login first!!',
			'buttons' : {
				'OK' : {
					'class' : 'blue',
					'action' : function() {
						window.location.href = "manager_login.jsp";
					}

				}
			}
		});
	</script>
	<%
		}
	%>
</body>

</html>